package com.lenovo.newsapp.helper;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class NewsSQLiteOpenHelper extends SQLiteOpenHelper {

	public static final int VERSION = 1;
	public static final String DB_NAME = "lenovonewsapp_db.sqlite";
		
	//新闻
	public static final String NEWS_TABLE = "news";
	public static final String NEWS_ID = "id";
	public static final String NEWS_TITLE = "title";
	public static final String NEWS_SUMMARY = "summary";
	public static final String NEWS_THUMBNAIL = "newsThumbnail";
	public static final String NEWS_AUTHOR = "author";
	public static final String NEWS_KEYWORD = "keyword";
	public static final String NEWS_LASTUPDATETIME = "lastUpdateTime";
	public static final String NEWS_IMGFRIST = "imgFrist";
	public static final String NEWS_IMGSECEND = "imgSecend";
	public static final String NEWS_IMGTHIRD = "imgThird";
	public static final String NEWS_CONTENT = "content";
	public static final String NEWS_IMGSIZE = "imgSize";
	public static final String NEWS_TYPE = "type";

	public NewsSQLiteOpenHelper(Context context) {
		super(context, DB_NAME, null, VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		dropAndCreate(db);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub

	}

	private void dropAndCreate(SQLiteDatabase db) {
		db.execSQL("drop table if exists " + NEWS_TABLE + ";");
		createTable(db);
	}

	private void createTable(SQLiteDatabase db) {
	
		db.execSQL("create table " + NEWS_TABLE + " (" + 
				NEWS_ID + " String primary key not null, " +
				NEWS_TITLE + " text, " + 
				NEWS_SUMMARY + " text, " + 
				NEWS_THUMBNAIL + " text, " + 
				NEWS_AUTHOR + " text, " + 
				NEWS_KEYWORD + " text, " + 
				NEWS_LASTUPDATETIME + " text, " + 
				NEWS_IMGFRIST + " text, " + 
				NEWS_IMGSECEND + " text, " + 
				NEWS_IMGTHIRD + " text, " + 
				NEWS_CONTENT + " text, " + 
				NEWS_TYPE + " text, " + 
				NEWS_IMGSIZE + " text " +" );"
				
				);

	}

}
